package i18n;

import java.text.DateFormat;
import java.text.MessageFormat;
import java.text.NumberFormat;
import java.util.Date;
import java.util.Locale;
import java.util.ResourceBundle;

public class MessageFormatTest {
	public static void main(String[] args) {
		formatDate();
		formatNumber();
		NumberFormatTest();
	}
	/**
	 * format number and currency
	 */
	private static void NumberFormatTest() {
		double money=100000000000000.05;
		NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.CHINA);
		System.out.println(nf.format(money));
		nf=NumberFormat.getInstance(Locale.GERMAN);
		System.out.println(nf.format(100000000000000.05));
	}

	private static void formatDate() {
		Date date = new Date();
		DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL,Locale.CHINA);
		System.out.println(df.format(date));
	}

	private static void formatNumber() {
		ResourceBundle rb = ResourceBundle.getBundle("i18n/res",Locale.CHINA);
		String len=rb.getString("length");
		//长度必须在{0}与{1}之间
		//格式化成：长度必须在3与8之间
		String length=MessageFormat.format(len, new String[]{"3","8"});
		System.out.println(length);
	}
}
